package com.johnguo.web.tcp_metr_perf_analy.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.johnguo.base.Page;
import com.johnguo.web.tcp_metr_perf_analy.service.TcpMetrPerfAnalyService;

import net.sf.json.JSONObject;
import com.johnguo.base.BaseController;


/**
 * TCP性能分析
 * 
 * @author 郭子华
 * @Date 2017-06-24 10:40:00
 *
 */
@Controller
@RequestMapping("/edpi/tcp_metr_perf_analy")
public class TcpMetrPerfAnalyController extends BaseController {
	@Resource
	private TcpMetrPerfAnalyService service;

	@RequestMapping
	public ModelAndView index() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		ModelAndView mv = new ModelAndView("edpi/tcp_metr_perf_analy/tcp_metr_perf_analy");
		String date = sdf.format(new Date());
		mv.addObject("beginDate", date + " 00:00:00");
		mv.addObject("endDate", date + " 23:59:59");
		return mv;
	}

	@RequestMapping("query")
	@ResponseBody
	public String query(HttpServletRequest request) {
		JSONObject requestParam = JSONObject.fromObject(request.getParameter("param"));
		JSONObject json = new JSONObject();
		Map<String, Object> param = new HashMap<String, Object>();
		Page page = bindPageData(request);
		param.put("page", page);
		param.putAll(requestParam);
		try {
			Map<String,Object> resultMap = service.query(param);
			json.put("status", "ok");
			page.setTotalRecord(Integer.parseInt(resultMap.get("totalCount").toString()));
			
			json.put("allData", resultMap.get("pageData"));
			json.put("pageDate", toPageJson((List<Map<String, Object>>) resultMap.get("pageData"), page));
		} catch (Exception ex) {
			ex.printStackTrace();
			json.put("status", "fail");
		}
		return json.toString();
	}

}
